/*
 * SearchAdvancedModel.java
 *
 * Created on 3 de junio de 2006, 13:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package fmap.model;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.StringTokenizer;

/**
 * Clase que define los criterios de una busqueda avanzada
 * @author javi
 */
public class SearchAdvancedModel
{
    
    String name;
    Date dateIni;
    Date dateFin;
    long sizeIni = -1;
    long sizeFin = -1;
    String sizeType;
    GroupFile groupFile;
    String wordKey;
    String comment;
    boolean mayusMinus; // =true=> diferenciamos entre las mayusculas y minusculas en la busqueda por cualquier campo
    
    
    public SearchAdvancedModel ( String _name, String _dateIni, String _dateFin, String _sizeIni, 
                                 String _sizeFin, String _sizeType, GroupFile _groupFile, String _wordKey, String _comment,
                                 boolean _mayusMinus)
    {
        
        name        = _name;
        mayusMinus  =   _mayusMinus;
        
        DateFormat format = new SimpleDateFormat ("dd/MM/yyyy");
        
        try
        {
            if ( !_sizeIni.equals ("") )  sizeIni = new Long ( _sizeIni ).longValue ();
        }
        catch (Exception e)
        {
            System.out.println ( e.toString () );
        }
        
        try
        {
            if ( !_sizeFin.equals ("") )  sizeFin = new Long ( _sizeFin ).longValue ();
        }
        catch (Exception e)
        {
            System.out.println ( e.toString () );
        }
        
        try
        {
            if( !_dateIni.trim ().equals ("") ) dateIni = format.parse ( _dateIni.trim () );
        }
        catch (Exception e)
        {
            System.out.println ( e.toString () );
        }
        
        try
        {
            if( !_dateFin.trim ().equals ("") ) dateFin = format.parse ( _dateFin.trim () );
        }
        catch (Exception e)
        {
            System.out.println ( e.toString () );
        }
        
        groupFile   = _groupFile;
        sizeType    = _sizeType;
        wordKey     = _wordKey;
        comment     = _comment;
    }
    
    
    public String getName ()
    {
        return name;
    }
    
    public boolean getMayusMinus()
    {
        return mayusMinus;
    }

    public long getSizeIni ()
    {
        if( sizeIni < 0 )   return -1;
        else                return sizeIni;
    }

    public long getSizeFin ()
    {
        if( sizeFin < 0 )   return -1;
        else                return sizeFin;
    }
    
    public Date getDateIni ()
    {
        if( dateIni != null )   return dateIni;
        else                    return null;
    }
    
    public Date getDateFin ()
    {
        if( dateFin != null )   return dateFin;
        else                    return null;
    }
    
    public java.sql.Date getDateIniSql ()
    {
        if( dateIni != null )
        {
            java.sql.Date sqlDate = new java.sql.Date (dateIni.getTime ());
            return sqlDate;
        }
        else
        {
            return null;
        }
    }

    public java.sql.Date getDateFinSql ()
    {
        if( dateFin != null )
        {
            java.sql.Date sqlDate = new java.sql.Date (dateFin.getTime ());
            return sqlDate;
        }
        else
        {
            return null;
        }
    }
    
    public String getSizeType ()
    {
        return sizeType;
    }

    
    /**
     * Devuelve un array de palabras clave
     * se separan por comas
     */
    public String[] getAWordKey ()
    {
        String[] aWordKey = wordKey.split (",");

        return aWordKey;
    }


    public String getWordKey ()
    {
        return wordKey;
    }
    
    public String getComment ()
    {
        return comment;
    }

    public GroupFile getGroupFile ()
    {
        return groupFile;
    }

}